//
//  PartnerDetailHeadView.m
//  beautyLamp
//
//  Created by Tam Kwok To Michael on 2017/8/21.
//  Copyright © 2017年 Tam Kwok To Michael. All rights reserved.
//
#import "XLCircleProgress.h"
#import "PartnerDetailHeadView.h"
#import "BLHeader.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "Partner.h"

@interface PartnerDetailHeadView ()
@property (weak, nonatomic) IBOutlet UIImageView *iconImage;
@property (weak, nonatomic) IBOutlet UIImageView *bgImage;

@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *telLabel;
@property (weak, nonatomic) IBOutlet UILabel *signLabel;
@property (weak, nonatomic) IBOutlet UIView *progressView;
@property (nonatomic, strong) XLCircleProgress *progress;
@property (weak, nonatomic) IBOutlet UIView *stroeProgressbg;
@property (weak, nonatomic) IBOutlet UIView *saleProgressbg;
@property (weak, nonatomic) IBOutlet UILabel *storeClassLabel;
@property (weak, nonatomic) IBOutlet UILabel *saleClassLable;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *storePgWidth;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *salePgWidth;

@end

@implementation PartnerDetailHeadView

+ (instancetype) partnerDetailHeadView {
    PartnerDetailHeadView *headView = [[[NSBundle mainBundle] loadNibNamed:@"PartnerDetailHeadView" owner:nil options:nil] lastObject];
    return headView;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    [self setupUI];
}

- (void)setupUI {
    self.progress = [[XLCircleProgress alloc] initWithFrame:CGRectMake(0, 0, 120, 120)];
    self.progress.progress = [self.partner.ratio floatValue] * 0.1;
   // NSLog(@"%f",[self.partner.ratio floatValue] * 0.1);
    [self.progressView addSubview:self.progress];
    self.progressView.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0];
    //设置渐变色
    CAGradientLayer *gradientLayer = [[CAGradientLayer alloc] init];
    //gradientLayer.colors = @[(__bridge id) mRGBToColor(0xff8800).CGColor,(__bridge id)mRGBToColor(0xff5100).CGColor];
    [gradientLayer setColors:[NSArray arrayWithObjects:(id)[RGB(255, 151, 0) CGColor],(id)[RGB(255, 203, 0) CGColor], nil]];
    //位置x,y    自己根据需求进行设置   使其从不同位置进行渐变
    gradientLayer.startPoint = CGPointMake(0, 0);
    gradientLayer.endPoint = CGPointMake(1, 0);
    gradientLayer.frame = CGRectMake(0, 0, CGRectGetWidth(self.stroeProgressbg.frame), CGRectGetHeight(self.stroeProgressbg.frame));
    [self.stroeProgressbg.layer addSublayer:gradientLayer];
    [self.saleProgressbg setBackgroundColor:[UIColor colorWithRed:50.0/255.0f green:50.0/255.0f blue:50.0/255.0f alpha:1]];
}

- (void)setPartner:(Partner *)partner {
    _partner = partner;
    [self updateUI];
}

- (void)updateUI {
    self.progress.progress = [self.partner.ratio floatValue] * 0.1;
    //NSLog(@"%f",[self.partner.ratio floatValue] * 0.1);
    self.storePgWidth.constant = [self.partner.ratio floatValue] * 10;
    self.salePgWidth.constant = (10 - [self.partner.ratio floatValue])* 10;
    [self.iconImage sd_setImageWithURL:[NSURL URLWithString:self.partner.headImg] placeholderImage:[UIImage imageNamed:@"icon"]];
    //高斯模糊
    [self.bgImage sd_setImageWithURL:[NSURL URLWithString:self.partner.headImg] placeholderImage:[UIImage imageNamed:@"icon"]];
    UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
    UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect];
    effectView.frame = self.bgImage.frame;
    [self.bgImage addSubview:effectView];
    self.nameLabel.text = [NSString stringWithFormat:@"用户名：%@",self.partner.name];
    self.telLabel.text = [NSString stringWithFormat:@"电话：%@",self.partner.tel];
    self.signLabel.text = self.partner.signature;
    BOOL isStore = [self.partner.userClass integerValue] == 1 ? YES : NO;
    if(isStore) {
        self.saleClassLable.text = @"我:";
    }else {
        self.storeClassLabel.text = @"我:";
    }
}
@end
